<?php
include("../includes/common.php");
if($islogin2==1){}else exit("<script language='javascript'>window.location.href='./login.php';</script>");
include './head.php';
$uid=$rs=$DB->query("select * from pay_user WHERE name={$pid}");
 if($conf['usera']==0){
      exit("<script language='javascript'>alert('本站管理员暂未开启商户转账功能，如有疑问请联系客服！');window.location.href='./';</script>");
    }
foreach($uid as $res){
 $usid=$res['id'];
}
$user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$user_IP = ($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];

$my=isset($_GET['my'])?$_GET['my']:null;
if($my=='zhuan'){
$user=$_POST['id'];
$money=$_POST['money'];
$pass=$_POST['pass'];
$ip=$user_IP;
$row=$DB->query("select * from pay_user where id='$user' limit 1")->fetch();
if (!$row) {
exit("<script language='javascript'>alert('转账ID不存在！');history.go(-1);</script>");
}elseif($user==$userrow['id']){
  exit("<script language='javascript'>alert('不能给自己转账！');history.go(-1);</script>");
}elseif($userrow['pass']==null){
exit("<script language='javascript'>alert('请还未设置支付密码！');history.go(-1);</script>");
}elseif(md5($pass) != $userrow['pass']){
  exit("<script language='javascript'>alert('支付密码错误！');history.go(-1);</script>");
}elseif($userrow['money'] < $money){
  exit("<script language='javascript'>alert('账户余额不足！');history.go(-1);</script>");
}elseif($userrow['usera']==1){
  exit("<script language='javascript'>alert('你的商户异常被冻结转账功能！');history.go(-1);</script>");
}else{
  $zhuan=$DB->query("update pay_user set money=money+{$money} where id='{$user}'");
  $zhuans=$DB->query("update pay_user set money=money-{$money} where id='{$usid}'");
  if($zhuan and $zhuans){
    $DB->query("insert into `pay_userpay` (`uid`,`pid`,`money`,`time`,`ip`) values ('".$user."','".$usid."','".$money."','".$date."','".$ip."')");
    exit("<script language='javascript'>alert('转账成功！');history.go(-1);</script>");
  }else{
    exit("<script language='javascript'>alert('转账失败！');history.go(-1);</script>");
  }
}
}
?>
<div class="clearfix"></div>  
  <div class="content-wrapper">
    <div class="container-fluid">
     <div class="row pt-2 pb-2">
        <div class="col-sm-9">
            <h4 class="page-title">商户转账</h4>
            <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="javaScript:void();">商户</a></li>
            <li class="breadcrumb-item"><a href="javaScript:void();">转账</a></li>
         </ol>
       </div>
     </div>
      <div class="row">
        <div class="col-lg-5">
          <div class="card">
            <div class="card-body">
                <h6 class="form-header text-uppercase">
                  <i class="fa fa-user-circle-o"></i>
                   商户信息
                </h6>
                <div class="form-group row">
                  <label for="input-1" class="col-sm-2 col-form-label">商户ID</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" value="<?php echo $usid;?>" disabled>
                  </div>
                </div>
                <div class="form-group row">
                  <label for="input-2" class="col-sm-2 col-form-label">商户余额</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" value="<?php echo $userrow['money']?>" disabled>
                  </div>
                </div>
                
            <div class="form-group row">
                  <label for="input-4" class="col-sm-2 col-form-label">支付密码</label>
                  <div class="col-sm-10">
                    <input type="password" class="form-control" id="pass" name="pass" value="******" required>
                  </div>
                </div>
                 <div class="form-group row">
                      <label class="col-lg-3 col-form-label form-control-label"></label>
                      <div class="col-lg-9">
                       <input type="button" isbind="<?php if($userrow['pass'])echo 1;else{echo 2;} ?>"  id="checkbind" value="<?php if($userrow['pass'])echo "修改密码";else echo "添加密码";  ?>" class="btn btn btn-danger  waves-effect waves-light m-1">
                         </div>
                        </div>
            </div>
          </div>
        </div>
         <div class="col-lg-6">
          <div class="card">
            <div class="card-body">
                <h6 class="form-header text-uppercase">
                  <i class="fa fa-user-circle-o"></i>
                   商户转账
                </h6>
                <form action="./Transfer.php?my=zhuan" method="POST">
                <div class="form-group row">
                  <label for="input-1" class="col-sm-2 col-form-label">ID</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="id" value="" required>
                  </div>
                </div>
                <div class="form-group row">
                  <label for="input-2" class="col-sm-2 col-form-label">金额</label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="money" value="" oninput ="value=value.replace(/[^\d]/g,'')" required>
                  </div>
                </div>
                
            <div class="form-group row">
                  <label for="input-4" class="col-sm-2 col-form-label">支付密码</label>
                  <div class="col-sm-10">
                    <input type="password" class="form-control" name="pass" value="" required>
                  </div>
                </div>
                 <div class="form-group row">
                      <label class="col-lg-3 col-form-label form-control-label"></label>
                      <div class="col-lg-9">
                       <input type="submit" value="确定转账" class="btn btn-secondary btn-square waves-effect waves-light m-1">
                         </div>
                        </div>
              </form>
            </div>
          </div>
        </div>
      </div>
 <div class="col-lg-12">
          <div class="card">
            <div class="card-header text-uppercase">关于商户转账注意事项：</div>
             <div class="card-body">
                <ul class="list-group">
              <li class="list-group-item list-group-item-primary">1.当商户商户余额不足输入的转账金额，切勿频繁转账恶意转账一但被系统风控将永久封停转账功能！</li>
              <li class="list-group-item list-group-item-primary">2.如被风控封停转账功能的商户，官方将不予解封，如有疑问请联系官方客服！<br/></li>
              <li class="list-group-item list-group-item-primary">
              3.在转账前请仔细输入对方正确的商户账号，切勿输错，输错一但转账成功，请在3小时内联系客服追回款项，超过3小时后果自负
              </li>
              <li class="list-group-item list-group-item-primary">
              4.在转账前请设置好您的支付密码，设置后请保管好您的支付密码，切勿泄露给他人，一但泄露支付密码发生的资金损失我们概不负责
              </li>
                  </ul>
             </div>
          </div>
        </div>

</div>
</div>
<script>
$("#checkbind").click(function(){
            if($(this).attr('isbind')==1)
                situationshow("yanz");
            else
                situationshow("yanz2");
            $.ajax({
                type : "GET",
                url : "ajax2.php?act=checkbind",
                dataType : 'json',
                success : function(data) {
                    if(data.code == 1){
                        
                    }else if(data.code == 2){
                        
                    }else{
                        layer.alert(data.msg);
                    }
                }
            });
        });
  
    function situationshow(situation){
            layer.open({
                type: 1,
                skin: 'layui-layer-rim', //加上边框
                area: ['420px', '250px'], //宽高
                btn:['确认','关闭'],
                title:'验证密保信息',
               content: "<div class=\"form-group row\">\n" +
                    "    <label class=\"col-lg-3 col-form-label form-control-label\">密保邮箱：</label>\n" +
                    "    <div class=\"col-lg-8\">\n" +
                    "        <input id='email-use' type=\"email\" style='background:white;' name=\"title\" lay-verify=\"title\" <?php if($userrow['email'])echo 'readonly';  ?> autocomplete=\"off\" value=\"<?php echo $userrow['email'];?>\" placeholder=\"请输入邮箱\" class=\"form-control\">\n" +
                    "    </div>\n" +
                    "</div>\n" +
                    "<div class=\"layui-form-item\" style='white-space:nowrap;'>\n" +
                    "\n" +

                    "        <input id='veify-win' type=\"text\" name=\"title\" lay-verify=\"title\" autocomplete=\"off\" placeholder=\"请输入验证码\"  style=\"float:left;width:72%;background:white;\" class=\"form-control\">\n" +

                    "    <button class=\"btn btn btn-danger  waves-effect waves-light m-1\" id=\"sendver_win\"  style='float:right'>获取验证码</button>\n" +
                    "</div>",
                yes:function(){
                    var veify=$('#veify-win').val();
                    if(''==veify){
                        layer.alert('请输入验证码！');
                        return false;
                    }
                    $.post('/user/ajax2.php?act=verifycode',{code:veify},function(data){
                        if(data.code=='-1'){
                            layer.alert(data.msg);

                        }else{

                           
                            $.post('/user/ajax2.php?act=edit_pass',{pass:$('#pass').val()},function(datas){
                                if(datas.code=='1'){
                                    layer.msg('操作成功');
                                    setTimeout(function(){
                                        location.reload();
                                    },800);
                                }else{
                                    layer.alert(datas.msg);
                                }
                            });

                        }



                    });

                } ,success(){
                    $('#sendver_win').click(function(){
                        sendver_win(situation);
                    });

                }

            });
        }
        /*获取验证码*/
        function sendver_win(situation){

            var ema=$('#email-use').val();
            if(ema==""){
                layer.alert("请输入邮箱");
                return false;
            }

            var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;

            if(myReg.test(ema)){

            }else{
                layer.alert("邮箱格式不对!");
                return false;
            }


            $.ajax({
                type : "POST",
                url : "ajax2.php?act=sendcode",
                data : {
                    situation:situation,
                    email:ema
                },
                dataType : 'json',
                success : function(data) {

                    if(data.code == 0){
                        layer.msg('发送成功，请注意查收！');

                        set_sendemail_time($('#sendver_win'));
                    }else{
                        layer.alert(data.msg);

                    }
                }
            });

        }
        function set_sendemail_time(th){
            th.attr('disabled',true);
            var time=60;
            th.prev().css("width",'60%');
            th.html(time+' 秒后可再次发送');
            var seti1=setInterval(function(){
                if(time--!=0){
                    th.html(time+' 秒后可再次发送');
                }else{
                    th.attr('disabled',false);
                    clearInterval(seti1);
                    th.prev().css("width",'72%');
                    th.html('获取验证码');
                }
            },1000);
        }




</script>

<?php include './foot.php';?>